const express = require('express')
const morgan = require('morgan')
const cors = require('cors')
const router = require('./router')
const errorHandler = require('./middleware/error-handler')

const app = express()

app.use(morgan('dev'))

app.use(express.json())
app.use(express.static('public'))

app.use(cors())

const PORT = process.env.PORT || 3000

app.use('/api', router)

//挂载统一处理服务端错误中间件
app.use(errorHandler())


app.listen(PORT, (req, res)=>{
  console.log('Server is running to http://localhost:3000')
})